package cn.stylefeng.guns.modular.app.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.DateUtil;
import cn.stylefeng.guns.modular.app.entity.MovingPalletsmerge;
import cn.stylefeng.guns.modular.app.model.params.MovingPalletsmergeParam;
import cn.stylefeng.guns.modular.app.service.MovingPalletsmergeService;
import cn.stylefeng.guns.modular.basic.entity.BasicArea;
import cn.stylefeng.guns.modular.basic.entity.BasicGoods;
import cn.stylefeng.guns.modular.basic.entity.BasicPosition;
import cn.stylefeng.guns.modular.basic.entity.BasicTray;
import cn.stylefeng.guns.modular.basic.model.params.BasicTrayParam;
import cn.stylefeng.guns.modular.basic.service.*;
import cn.stylefeng.guns.modular.storage.entity.StorageStock;
import cn.stylefeng.guns.modular.storage.model.params.StorageStockParam;
import cn.stylefeng.guns.modular.storage.model.result.StorageStockResult;
import cn.stylefeng.guns.modular.storage.service.StorageStockService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.StringUtils;
import org.springframework.util.unit.DataUnit;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.*;

/**
 * 移库和托控制器
 */
@Controller
@RequestMapping("/movingPalletsmerge")
public class MovingPalletsmergeController extends BaseController {

    private String PREFIX = "/app/movingPalletsmerge";

    @Autowired
    private BasicGoodsService basicGoodsService;

    @Autowired
    private MovingPalletsmergeService movingPalletsmergeService;

    @Autowired
    private UserService userService;

    @Autowired
    private StorageStockService storageStockService;

    @Resource
    private BasicTrayService basicTrayService;

    @Autowired
    private BasicWarehouseService basicWarehouseService;

    @Autowired
    private BasicPositionService basicPositionService;

    @Autowired
    private BasicAreaService basicAreaService;

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/movingPalletsmerge.html";
    }

    /**
     * 新增接口
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(MovingPalletsmergeParam movingPalletsmergeParam) {
        this.movingPalletsmergeService.add(movingPalletsmergeParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(MovingPalletsmergeParam movingPalletsmergeParam) {
        this.movingPalletsmergeService.update(movingPalletsmergeParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(MovingPalletsmergeParam movingPalletsmergeParam) {
        this.movingPalletsmergeService.delete(movingPalletsmergeParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(MovingPalletsmergeParam movingPalletsmergeParam) {
        MovingPalletsmerge detail = this.movingPalletsmergeService.getById(movingPalletsmergeParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/cxlist")
    public LayuiPageInfo list(MovingPalletsmergeParam movingPalletsmergeParam, String condition) {
    	User user = userService.getcurrentUser();
    	movingPalletsmergeParam.setDeptId(user.getDeptId());
        return this.movingPalletsmergeService.findPageBySpec(movingPalletsmergeParam, condition, user.getOperateId());
    }

    /**
     * 根据库位查询商品信息
     */
    @RequestMapping("/list")
    @ResponseBody
    public List<StorageStockResult> list(StorageStockParam storageStockParam) {
    	User user = userService.getcurrentUser();
    	storageStockParam.setDeptId(user.getDeptId());
        List<StorageStockResult> iii =this.storageStockService.findGoodsList(storageStockParam,user.getOperateId());
        return iii;
    }

    /**
     * 根据库位查询商品信息查询托盘
     */
    @RequestMapping("/trayList")
    @ResponseBody
    public List<StorageStockResult> trayList(StorageStockParam storageStockParam) {
        return this.storageStockService.findTrayList(storageStockParam);
    }


}


